home *** CD-ROM | disk | FTP | other *** search
- Path: news.walrus.com!news
- From: fjordao@walrus.com (Felipe Jordao)
- Newsgroups: comp.lang.c++
- Subject: Re: [Q] Dynamically allocating memory for a char*
- Date: Tue, 30 Jan 1996 22:41:42 GMT
- Organization: HAC
- Message-ID: <4em6te$pmj@walrus2.walrus.com>
- References: <4dmn1i$10t@walrus2.walrus.com> <NITIN.96Jan19095012@more.eng.sun.com> <4doph6$507@newsroom.hitc.com>
- NNTP-Posting-Host: p12.ts1.walrus.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- psand@eos.hitc.com (G. Patrick Sand) wrote:
- : >In article <4dmn1i$10t@walrus2.walrus.com> fjordao@walrus.com (Felipe
- : Jordao)
- : >writes:
- : How about this:
- : use the cin.get( char* buf, int length, char term) method
- : This reads into a buffer (buf) up to length bytes and null-terminates it
- : (dropping the last byte if the stream read in has length non-null
- : characters), until it hits the term character.
- : Just pick a buffer size (like 512 or 1024) that you know they have no
- : right to exceed and you then manipulate the buffer to get your string...
- : I found this in section 10.3.1 (p. 332) of The C++ Programming Language
- : (2nd Edition) by Stroustrup (ISBN 0-201-53992-6)--mine is copyrighted
- : 1991
-
- Thanks for the tip. I had seen this info and had even bought a C++
- book only on IOStreams (with a fish on the front) that's pretty good.
- Maybe I'm missing the point here. If I use a buffer wouldn't that
- still mean that I have to allocate 512 or X amount of memory? Will
- the buffer disappear immeadiately after I read the string and assign
- it? I was trying to get away with assigning just the right amount of
- memory. Or am I being stupidly picky? ;)
-
- Felipe
-
-